package com.milowski.monos.component;


import com.milowski.monos.*;
import com.milowski.monos.binomial.*;
import org.infoset.component.Component;
import org.infoset.component.ItemFilterComponent;
import org.infoset.xml.Document;
import org.infoset.xml.Element;
import org.infoset.xml.InfosetFactory;
import org.infoset.xml.ItemConstructor;
import org.infoset.xml.ItemDestination;
import org.infoset.xml.Name;
import org.infoset.xml.XMLException;
import org.infoset.xml.filter.SubtreeFilter;

/**
 *
 * @author R. Alexander Milowski
 */
public class TransposeMatrixComponent extends MonosComponentBase {
   static final Name componentName = InfosetFactory.createName(XML.STEPS_NAMESPACE,"transpose-matrix");
   static Name [] subtreeNames = { XML.matrixName };

   public static class ComponentFilter extends SubtreeFilter {
      
      ComponentFilter() {
         super(subtreeNames);
      }
      public void process(Document doc) 
         throws XMLException
      {
         Element top = doc.getDocumentElement();
         MatrixBasis matrix = MatrixBasis.fromXML(top);
         matrix.transpose();
         ItemConstructor constructor = InfosetFactory.getDefaultInfoset().createItemConstructor(doc.getBaseURI());
         matrix.toXML(constructor,output);
      }
   }
   
   /** Creates a new instance of KernelBasisComponent */
   public TransposeMatrixComponent()
   {
      super(componentName);
   }
   
   public Component newInstance() 
      throws XMLException
   {
      final ComponentFilter filter = new ComponentFilter();
      return new ItemFilterComponent(name,vendor,version,filter,inputPortName,outputPortName);
   }
   
}
